package pers.xiqingbo.dao.impl;

import pers.xiqingbo.dao.BaseDao;
import pers.xiqingbo.dao.UserDao;
import pers.xiqingbo.pojo.User;

/**
 * @PackageName: pers.xiqingbo.dao.impl
 * @ClassName: UserDaoImpl
 * @Description: 用户数据访问层实现类
 * @Author: Schieber
 * @Date: 2021/2/3 上午 0:31
 */
public class UserDaoImpl extends BaseDao implements UserDao {

    @Override
    public User queryUserByUsername(String username) {
        String sql = "select `username`,`password`,`mailbox` from `t_user` where `username` = ?";
        return queryForOne(User.class, sql, username);
    }

    @Override
    public User queryUserByUsernameAndPassword(String username, String password) {
        String sql = "select `id`,`username`,`password`,`mailbox` from `t_user` where `username` = ? and `password` = ?";
        return queryForOne(User.class, sql, username, password);
    }

    @Override
    public int saveUser(User user) {
        String sql = "insert into t_user(`username`,`password`,`mailbox`) values(?,?,?)";
        return update(sql, user.getUsername(), user.getPassword(), user.getMailbox());
    }
}
